package com.duolaibei.business.view.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.duolaibei.business.R;
import com.duolaibei.business.base.BaseActivity;
import com.duolaibei.business.config.Preferences;
import com.duolaibei.business.utils.CommonUtil;
import com.duolaibei.business.utils.PreferenceUtil;
import com.duolaibei.business.utils.inject.Inject;

/**
 * Created by xlm on 2017/11/13 0013
 */

public class OutTimeSetActivity extends BaseActivity {

    @Inject(R.id.back)
    private RelativeLayout mLayoutBack;
    @Inject(R.id.title)
    private TextView mViewTitle;

    @Inject(R.id.outtime_time)
    private EditText mEditTextTime;
    @Inject(R.id.outtime_setup_confirm)
    private TextView mTextViewConfirm;

    String time;//超时时间

    @Override
    protected void onSetContentView() {
        setContentView(R.layout.activity_outtime);
    }

    @Override
    protected void initViews() {
        mViewTitle.setText("超时设置");
    }

    @Override
    protected void afterOnCreate(Bundle savedInstanceState) {
        time = String.valueOf(PreferenceUtil.getParam(Preferences.OUTTIME, ""));
        if (!CommonUtil.isEmpty(time)) {
            mEditTextTime.setText(String.format("%1$s秒", time));
        }
    }

    @Override
    protected void onSetListener() {
        mLayoutBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mTextViewConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setOutTimeLong();
            }
        });
    }

    /**
     * 设置超时时间
     */
    private void setOutTimeLong() {
        String time = mEditTextTime.getText().toString();
        if (!CommonUtil.isEmpty(time)) {
            PreferenceUtil.setParam(Preferences.OUTTIME, time);
            showToast("设置成功");
        }
    }

}
